package com.itheima.pojo;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author wz
 * @description:
 * @date 2021-10-30
 */
public class TestMain {
    public static void main(String[] args) {
        //初始化ioc容器
        ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
        //根据bean的类型创建bean
//        UserService bean = (UserService) ctx.getBean("userService2");
//        bean.add();

        //测试单例,期望true
        Object o1 = ctx.getBean("userService1");
        Object o2 = ctx.getBean("userService1");
        System.out.println(o1==o2);

        //测试多例,期望fase 在多例模式下,spring只负责创建对象,不负责维护对象,jvm自动维护,对象一旦不被使用
        //就会被垃圾回收
        Object o3 = ctx.getBean("userService3");
        Object o4 = ctx.getBean("userService3");
        System.out.println(o3==o4);
    }
}
